home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / bcopy / bcopy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-30  |  2.2 KB  |  87 lines

  1. /* 
  2.  * bcopy.c --
  3.  *
  4.  *    Benchmark program to measure memory bandwidth.
  5.  *    Invoke with no arguments.  It will make repeated
  6.  *    calls to bcopy with different size buffers and
  7.  *    print memory bandwidth as a function of buffer
  8.  *    size.
  9.  *    
  10.  *
  11.  * Copyright 1989 Regents of the University of California
  12.  * Permission to use, copy, modify, and distribute this
  13.  * software and its documentation for any purpose and without
  14.  * fee is hereby granted, provided that the above copyright
  15.  * notice appear in all copies.  The University of California
  16.  * makes no representations about the suitability of this
  17.  * software for any purpose.  It is provided "as is" without
  18.  * express or implied warranty.
  19.  */
  20.  
  21. #ifndef lint
  22. static char rcsid[] = "$Header: /sprite/src/benchmarks/bcopy/RCS/bcopy.c,v 1.2 90/03/30 14:45:55 ouster Exp $ SPRITE (Berkeley)";
  23. #endif /* not lint */
  24.  
  25. #include <stdio.h>
  26. #include <sys/time.h>
  27. #include <sys/resource.h>
  28.  
  29. /*
  30.  * Different amounts to copy at once:
  31.  */
  32.  
  33. int sizes[] =
  34.     {10, 50, 100, 500, 1000, 5000, 10000, 50000, 100000, 200000, -1};
  35.  
  36. #define MAX_AT_ONCE 500000
  37. char src[MAX_AT_ONCE], dst[MAX_AT_ONCE];
  38.  
  39. main(argc, argv)
  40.     int argc;
  41.     char **argv;
  42. {
  43.     register int *sizePtr;
  44.     struct rusage begin, end;
  45.     struct timeval start, stop;
  46.     int micros, totalBytes, bytesSoFar, count;
  47.     double mbSec;
  48.  
  49.     if (argc > 1) {
  50.     totalBytes = 1000000*atoi(argv[1]);
  51.     } else {
  52.     totalBytes = 5000000;
  53.     }
  54.  
  55.     for (sizePtr = sizes; *sizePtr > 0; sizePtr++) {
  56. #ifdef GETRUSAGE
  57.     getrusage(RUSAGE_SELF, &begin);
  58. #else
  59.     gettimeofday(&start, (struct timezone *) NULL);
  60. #endif
  61.  
  62.     for (bytesSoFar = 0; bytesSoFar < totalBytes;
  63.         bytesSoFar += count) {
  64.         count = totalBytes - bytesSoFar;
  65.         if (count > *sizePtr) {
  66.         count = *sizePtr;
  67.         }
  68.         bcopy(src, dst, count);
  69.     }
  70. #ifdef GETRUSAGE
  71.     getrusage(RUSAGE_SELF, &end);
  72.     micros = (end.ru_utime.tv_sec
  73.         - begin.ru_utime.tv_sec)*1000000
  74.         + (end.ru_utime.tv_usec - begin.ru_utime.tv_usec);
  75. #else
  76.     gettimeofday(&stop, (struct timezone *) NULL);
  77.     micros = 1000000*(stop.tv_sec - start.tv_sec)
  78.         + stop.tv_usec - start.tv_usec;
  79. #endif
  80.  
  81.     mbSec = totalBytes;
  82.     mbSec /= micros;
  83.     printf("Transfer size: %d, Mbytes/sec: %.2f\n", *sizePtr,
  84.         mbSec);
  85.     }
  86. }
  87.